var pageIndex = 0;
var pageSize = 6;
var dataResult = null;
mini.parse();

var tree = mini.get("teamTree");
var grid = mini.get("dockerGrid");


////////////////////
//标准方法接口定义
function SetData(data) {
    //初始化团队树
    $.ajax({
        url: GatewayUrl() + '/archives/teamTree/' + data.did,
        type: 'get',
        headers: {
            "Authorization": localStorage.getItem("token")
        },
        success: function(dt){
            if(dt.code === 200){
                tree.loadList(dt.data, "tid", "pid");
            }
        }
    })

}

function getDockerList(tid,pageIndex, pageSize) {
    $.ajax({
        url: GatewayUrl() + '/archives/initDockerList/' + tid,
        type: 'get',
        async: false,
        data: {
            "pageIndex": pageIndex,
            "pageSize": pageSize
        },
        headers: {
            "Authorization": localStorage.getItem("token")
        },
        success: function (dt) {
            if (dt.code === 200) {
                dataResult = mini.decode(dt.data);
            }
        }
    })
}

// 分页填充细节处理
function fillData(pageIndex, pageSize, dataResult, grid) {
    var data = dataResult.data, totalCount = dataResult.total;

    var arr = [];
    var start = pageIndex * pageSize, end = start + pageSize;
    for (var i = 0; i < dataResult.data.length; i++) {
        arr.push(dataResult.data[i]);
    }

    grid.setTotalCount(totalCount);
    grid.setPageIndex(pageIndex);
    grid.setPageSize(pageSize);

    grid.setData(arr);
    
    
}


tree.on("nodeselect", function (e) {
    getDockerList(e.node.tid,pageIndex + 1, pageSize);
    fillData(0, grid.getPageSize(), dataResult, grid);
    // grid.load({ tid: e.tid });

    /* 
    if (e.isLeaf) {
        grid.load({ dept_id: e.node.id });
    } else {
        grid.setData([]);
        grid.setTotalCount(0);
    }
    */
    
});

function GetData() {
    var row = grid.getSelected();
    return row;
}

function onRowDblClick(e) {
    onOk();
}

function CloseWindow(action) {
    if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
    else window.close();
}

function onOk() {
    CloseWindow("ok");
}
function onCancel() {
    CloseWindow("cancel");
}